package com.company.project.common.job.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.company.project.robot.entity.SendRecordEntity;
import com.company.project.robot.service.SendRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author ZYF
 * @date 2021/11/29 15:37
 */
@Component("SendWechatTask")
public class SendWechatTask {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    SendRecordService sendRecordService;

    public void run(String params) throws ParseException {
        logger.info("============开始发送微信信息执行========");
        List<SendRecordEntity> list = new ArrayList<>();
        LambdaQueryWrapper<SendRecordEntity> queryWrapper =new LambdaQueryWrapper<>();
        queryWrapper.eq(SendRecordEntity::getSendType,0).eq(SendRecordEntity::getStatus,0);
        List<SendRecordEntity> lists = sendRecordService.list(queryWrapper);
        for(SendRecordEntity sendRecord :lists){
            Date now = new Date();
            //compareTo()方法的返回值，date1小于date2返回-1，date1大于date2返回1，相等返回0
            int number = now.compareTo(sendRecord.getSendTime());
            if(number >= 0){
                list.add(sendRecord);
            }
        }
        for(SendRecordEntity sendRecord: list){
            sendRecordService.updateSendFile(sendRecord);
        }
        logger.info("============结束发送微信信息执行========");
    }

}
